/* eslint-disable no-empty-pattern */
import { api_delById, api_modifyAll, api_queryById } from '@/api/crud'

import {
  api_uploadSingle,
  api_uploadMulti,
  api_delByUuid,
  api_patch,
  api_downloadStream,
  api_downloadEntity,
  api_showImageByUuid,
  api_listPage,
  api_listAllByIdTask,
} from '@/api/sys_ul_file'

const pathName = 'file'

const state = {}

const mutations = {}

const actions = {
  // 上传单文件
  uploadFileSingle({}, paramsJson) {
    return new Promise((resolve, reject) => {
      api_uploadSingle(paramsJson)
        .then((response) => {
          resolve(response.data.data)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 上传多个文件
  uploadFileMulti({}, paramsJson) {
    return new Promise((resolve, reject) => {
      api_uploadMulti(paramsJson)
        .then((response) => {
          resolve(response.data.data)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 根据记录id删除文件
  delById({}, id) {
    return new Promise((resolve, reject) => {
      api_delById(pathName, id)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 根据文件的uuid删除一个已上传的文件
  delByUuid({}, uuid) {
    return new Promise((resolve, reject) => {
      api_delByUuid(uuid)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 修改全部
  modifyAll({}, fileObj) {
    return new Promise((resolve, reject) => {
      api_modifyAll(pathName, fileObj)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 修改tag/filename/remark
  patch({}, paramsJson) {
    return new Promise((resolve, reject) => {
      api_patch(paramsJson)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 以stream方式及文件uuid下载文件
  downloadStream({}, uuid) {
    return new Promise((resolve, reject) => {
      api_downloadStream(uuid)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 以entity方式及文件uuid下载文件
  downloadEntity({}, uuid) {
    return new Promise((resolve, reject) => {
      api_downloadEntity(uuid)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 根据图像文件uuid获取图片
  showImageByUuid({}, uuid) {
    return new Promise((resolve, reject) => {
      api_showImageByUuid(uuid)
        .then((response) => {
          resolve(response.data)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 根据id查询到一个对象全部资料
  queryById({}, id) {
    return new Promise((resolve, reject) => {
      api_queryById(pathName, id)
        .then((response) => {
          resolve(response.data.data)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 得到某任务所有附件
  listAllByIdTask({}, idTask) {
    return new Promise((resolve, reject) => {
      api_listAllByIdTask(idTask)
        .then((response) => {
          resolve(response.data.data)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 得到管理员上传到服务器上的文件分页数据
  listPage({}, paramsJson) {
    return new Promise((resolve, reject) => {
      api_listPage(paramsJson)
        .then((response) => {
          resolve(response.data.data)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
}
